//
//  LKWorkCustomListCell.m
//  YLHelper
//
//  Created by she1323 on 2018/4/17.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKWorkCustomListCell.h"

@implementation LKWorkCustomListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setViewLayers:self.orderBtn andborderColor:blueDefault];
    [self setViewLayers:self.foundOrderBtn andborderColor:blueDefault];
    [self setViewLayers:self.appointmentBtn andborderColor:orangDefault];
    [self setViewLayers:self.updateBtn andborderColor:orangDefault];
    [self setViewLayers:self.deletBtn andborderColor:lightGrayDefault];
    [self.deletBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(WIDTH * 0.146);
    }];
    [self.updateBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(WIDTH * 0.146);
    }];
    [self.appointmentBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(WIDTH * 0.146);
    }];
    [self.orderBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(WIDTH * 0.146);
    }];
    [self.foundOrderBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(WIDTH * 0.21);
        make.width.mas_equalTo(WIDTH * 0);
    }];
    _labelsView = [[LKWorkLabelView alloc] initWithFrame:self.bgView.bounds];
    _labelsView.isCustom = YES;
//    _labelsView.titleArray = @[@"客户编号：00321551",@"性别：女",@"证件类型：身份证",@"证件号码：623021199021253568"];
    [self.bgView addSubview:_labelsView];
    // Initialization code
}
/**
 设置圆角和边角
 
 */
-(void)setViewLayers:(UIView *)view andborderColor:(UIColor *)color{
    view.layer.borderColor = color.CGColor;
    view.layer.borderWidth = 1;
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
}
-(void)setModel:(LKCustomerModel *)model{
    self.updateBtn.hidden = NO;
    [self.updateBtn setTitle:@"编辑" forState:UIControlStateNormal];
    [self.orderBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.height.mas_equalTo(25);
        make.top.equalTo(self.linelineView.mas_bottom).offset(15);
        make.width.mas_equalTo(55);
    }];
    [self.appointmentBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.orderBtn.mas_left).offset(-15);
        make.height.mas_equalTo(25);
        make.top.equalTo(self.linelineView.mas_bottom).offset(15);
        make.width.mas_equalTo(55);
    }];
    [self.updateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.appointmentBtn.mas_left).offset(-15);
        make.height.mas_equalTo(25);
        make.top.equalTo(self.linelineView.mas_bottom).offset(15);
        make.width.mas_equalTo(55);
    }];
    [self.deletBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.updateBtn.mas_left).offset(-15);
        make.height.mas_equalTo(25);
        make.top.equalTo(self.linelineView.mas_bottom).offset(15);
        make.width.mas_equalTo(55);
    }];
    self.deletBtn.hidden = YES;
    self.updateBtn.hidden = YES;
    self.foundOrderBtn.hidden = YES;
    self.orderBtn.hidden = YES;
    self.appointmentBtn.hidden = YES;
    _model = model;
    self.nameLabel.text = model.customerName;
    self.customerTypeLabel.text = [self backTitleAccordingCustormerCategoryType:[model.custormerCategory integerValue]];
    self.customerTypeLabel.text = [NSString backTitleAccordingApprovalStatusType:[model.approvalStatus integerValue]];
    NSString *customerCode = [NSString stringWithFormat:@"%@%@",@"客户编号：",model.customerCode];
    NSString *sexType;
    if ([model.customerGender isEqual:@"0"]) {
        sexType = [NSString stringWithFormat:@"%@%@",@"性别：",@"男"];
    }else{
        sexType = [NSString stringWithFormat:@"%@%@",@"性别：",@"女"];
    }
    NSString *identCode = [NSString stringWithFormat:@"%@%@",@"证件号码：",model.identityId];
    _labelsView.isCustom = YES;
    NSString *identCatagory = [NSString stringWithFormat:@"%@%@",@"证件类型：",[self backTitleAccordingIdCatogaryType:[model.identitfyCategory integerValue]]];
    NSMutableArray *eidtsArraa = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < _model.cusButtonType.count; i++) {
        NSString *valuse = [NSString stringWithFormat:@"%@",_model.cusButtonType[i]];
        [eidtsArraa addObject:valuse];
    }
    
    for (NSString *value in eidtsArraa) {
        if ([value isEqual:@"0"]) {
            self.updateBtn.hidden = NO;
           [self.updateBtn setTitle:@"编辑" forState:UIControlStateNormal];
        }
        if ([value isEqual:@"1"]) {
            self.updateBtn.hidden = NO;
            [self.updateBtn setTitle:@"变更" forState:UIControlStateNormal];
        }
        if ([value isEqual:@"-1"]) {
            self.deletBtn.hidden = NO;
        }
        if ([value isEqual:@"2"]) {
            self.orderBtn.hidden = NO;
        }
        if ([value isEqual:@"3"]) {
            self.foundOrderBtn.hidden = NO;
        }
        if ([value isEqual:@"4"]) {
            self.appointmentBtn.hidden = NO;
        }
    }
    if (eidtsArraa.count == 1 && [eidtsArraa[0] isEqual:@"1"]) {
        [self.updateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.height.mas_equalTo(25);
            make.top.equalTo(self.linelineView.mas_bottom).offset(15);
            make.width.mas_equalTo(55);
        }];
    }
    
    
    
    
//    if ([_model.custormerCategory integerValue] == 1) {
//        //储备客户
//        self.orderBtn.hidden = NO;
//        self.updateBtn.hidden = NO;
//        self.foundOrderBtn.hidden = NO;
//        self.appointmentBtn.hidden = NO;
//        self.deletBtn.hidden = NO;
//    }else{
//        //订单客户
//        if ([_model.changgeOwner boolValue] && [_model.approvalStatus integerValue] != 1) {
//            self.deletBtn.hidden = YES;
//            self.orderBtn.hidden = YES;
//            self.foundOrderBtn.hidden = YES;
//            self.appointmentBtn.hidden = NO;
//            [self.updateBtn setTitle:@"变更" forState:UIControlStateNormal];
//            [self.updateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//                make.right.equalTo(self.contentView.mas_right).offset(-15);
//                make.height.mas_equalTo(25);
//                make.top.equalTo(self.linelineView.mas_bottom).offset(15);
//                make.width.mas_equalTo(55);
//            }];
//            [self.appointmentBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//                make.right.equalTo(self.updateBtn.mas_left).offset(-15);
//                make.height.mas_equalTo(25);
//                make.top.equalTo(self.linelineView.mas_bottom).offset(15);
//                make.width.mas_equalTo(55);
//            }];
//
//            if ([_model.approvalStatus integerValue] != -2) {
//                self.orderBtn.hidden = NO;
//                self.foundOrderBtn.hidden = NO;
//                [self.orderBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//                 make.right.equalTo(self.appointmentBtn.mas_left).offset(-15);
//                    make.height.mas_equalTo(25);
//                    make.top.equalTo(self.linelineView.mas_bottom).offset(15);
//                    make.width.mas_equalTo(55);
//                }];
//                [self.foundOrderBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//                    make.right.equalTo(self.orderBtn.mas_left).offset(-15);
//                    make.height.mas_equalTo(25);
//                    make.top.equalTo(self.linelineView.mas_bottom).offset(15);
//                    make.width.mas_equalTo(0.0);
//                }];
//            }
//        }else{
//            self.deletBtn.hidden = YES;
//            self.appointmentBtn.hidden = YES;
//            self.orderBtn.hidden = YES;
//            self.foundOrderBtn.hidden = YES;
//            self.updateBtn.hidden = YES;
////            [self.updateBtn setTitle:@"变更待审批" forState:UIControlStateNormal];
////            [self.updateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
////                make.right.equalTo(self.contentView.mas_right).offset(-15);
////                make.height.mas_equalTo(25);
////                make.top.equalTo(self.linelineView.mas_bottom).offset(15);
////                make.width.mas_equalTo(85);
////            }];
////            if ([self.updateBtn.titleLabel.text isEqual:@"变更待审批"]) {
////                self.updateBtn.hidden = YES;
////            }
//
//
//        }
//
//    }
    _labelsView.titleArray = @[customerCode,sexType,identCatagory,identCode];
    [_labelsView.tableview reloadData];
    
}
/**
 根据证件类型返回文字
 
 @param type 证件类型
 @return 文字
 */
-(NSString *)backTitleAccordingIdCatogaryType:(NSInteger)type{
    if (type == 1) {
        return @"身份证";
    }else if (type == 2){
        return @"护照";
    }else if (type == 3){
        return @"军人证件";
    }else if (type == 4){
        return @"港澳通行证";
    }else if (type == 5){
        return @"台胞证";
    }else if (type == 6){
        return @"营业执照";
    }
    return @"其他";
}

/**
 根据用户类型返回值

 @param type 用户类型
 @return 文字
 */
-(NSString *)backTitleAccordingCustormerCategoryType:(NSInteger)type{
    if (type == 1) {
        return @"储备客户";
    }else if (type == 2){
        return @"订单客户";
    }else if (type == 3){
        return @"APP注册客户";
    }
    return @"未知";
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
